use actix_files::Files;
use actix_web::{App, HttpServer};
use crate::{config::{HTML_DIR, WEB_ADDR}, error::IoErr};

mod codec;
mod api;
mod session;
mod events;

pub async fn init() -> Result<(), IoErr> {
    println!("web server:{}", WEB_ADDR);

    session::init();

    let app = || {
        let file_service = Files::new("/web", HTML_DIR)
            .index_file("index.html");
        
        App::new()
            .service(file_service)
            .configure(api::register)
        
    };

    HttpServer::new(app)
        .bind(WEB_ADDR)?
        .run()
        .await?;

    Ok(())
}









